using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SCS.Common.Models;
namespace SCS.DAL.Mapping
{
    public class ParentMap : EntityTypeConfiguration<Parent>
    {
        public ParentMap()
        {
            // Primary Key
            this.HasKey(t => t.parentID);

            // Properties
            this.Property(t => t.parentID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.parentName)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.gender)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(1);

            this.Property(t => t.mobile)
                .HasMaxLength(12);

            this.Property(t => t.tel)
                .HasMaxLength(12);

            this.Property(t => t.email)
                .HasMaxLength(80);

            // Table & Column Mappings
            this.ToTable("Parents");
            this.Property(t => t.parentID).HasColumnName("parentID");
            this.Property(t => t.parentName).HasColumnName("parentName");
            this.Property(t => t.gender).HasColumnName("gender");
            this.Property(t => t.mobile).HasColumnName("mobile");
            this.Property(t => t.tel).HasColumnName("tel");
            this.Property(t => t.email).HasColumnName("email");
            this.Property(t => t.userID).HasColumnName("userID");

            // Relationships
            this.HasOptional(t => t.MembershipUser)
                .WithMany(t => t.Parents)
                .HasForeignKey(d => d.userID);

        }
    }
}
